#include <iostream>
using namespace std;

/*
    多态三要素:
        1.父类指针或引用指向子类对象
        2.子类重写父类方法(ovrride).
        3.public继承
*/
class Person
{
public:
    Person()
    {
        cout << "Person()" << endl;
    }

    virtual ~Person()
    {
        cout << "~Person()" << endl;
    }

    void run ()
    {
        cout << "Person::run()" << endl;
    }

private:
    int m_age;
};

class Student : public Person
{
public:
    Student()
    {
        m_score = new int[10];
        cout << "student()" << endl;
    }

    ~Student() override
    {
        delete m_score;
        cout << "~student()" << endl;
    }

    void run()
    {
        cout << "Student::run()" << endl;
    }

    void study()
    {
        cout << "Student::study()" << endl;
    }
private:
    int * m_score;
};

int main()
{

    Student * p = new Student();
    delete p;

    
    Person* p1 = new Person();
    //Person*指向子类对象
    Person* p2 = new Student();

#if 0
    Student * stu1 = (Student * )p1;
    stu1->run();
    Student * stu2 = (Student * )p2;
    stu2->run();
#else
    Student * stu1 = dynamic_cast<Student *>(p1);
    cout << "stu1:" << stu1 << endl;

    Student * stu2 = dynamic_cast<Student *>(p2);
    cout << "stu2:" << stu2 << endl;

#endif
    return 0;
}